package com.gobi.consumer;

import com.gobi.consumer.api.ProviderApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@RestController
public class FeignConsumerApplication {
    @Autowired
    private ProviderApi providerApi;

    @Autowired
    FeignContext context;

    public static void main(String[] args) {
        SpringApplication.run(FeignConsumerApplication.class, args);
    }


    @GetMapping("consumer")
    public String consumer() {
        return "helle consumer";
    }

    //localhost:9092/consumer/provider
    @GetMapping("consumer/provider")
    public String provider(String name) {
        return "consumer->provider。" + providerApi.provider(name);
    }

    //localhost:9092/consumer/getUser
    @GetMapping("consumer/getUser")
    public String getUser(String name) {
        return "consumer->provider。" + providerApi.getUser(name);
    }

    @GetMapping("consumer/void")
    public String getUser() {
        providerApi.returnNull();
        return "consumer/void";
    }

    @GetMapping("consumer/void2")
    public String void2() {
        String returnNull2 = providerApi.returnNull2();
        return "consumer/void";
    }

    public void test(){
        //context.getInstances();
    }
}
